/*WziLu/4A0kO0uBbSHZ8lDgTpCkg49kx8vyf9NtVTXT1Eb3imR5AOucqegTL/biXC*/
import { PAGECODE, URL, FIELD } from '../../constance';
import initButtons from '../init/initButtonState';
import searchBtnClick from './searchBtnClick';

export default function (pageModel) {
    const { multiLang: { getMultiLangData }, toast, ajax, promptBox } = pageModel;
    const multiLangData = getMultiLangData();
    let rows = pageModel.get(PAGECODE.listTableId).getCheckedRows();
    // 如果没有选中行，则提示并返回，不进行任何操作
    if (rows.length <= 0) {
        toast({
            color: 'warning',
            content: multiLangData['4004POORDER-000067'] /* 国际化处理： 请选择需要提交的数据！*/
        });
        return;
    }

    promptBox({
        /* 国际化处理： 删除,确定要删除吗？*/
        color: "info",
        title: "收回",
        content: '确定要收回吗？',
        beSureBtnClick: () => {
            const pks = [], pkMapTs = {};
            rows.forEach(item => {
                let pk = item.data.values[FIELD.pk].value;
                pks.push(pk);
                pkMapTs[pk] = item.data.values[FIELD.ts].value;
            });
            let data = {
                pks,
                pkMapTs,
                pagecode: PAGECODE.cardCode,
            };
            // 发送请求
            ajax({
                url: URL.unCommit,
                data: data,
                success: (res) => {
                    if (res.success) {
                        initButtons(pageModel);
                        //批量
                        toast(multiLangData['4004POORDER-000097']);
                        searchBtnClick.call(null, pageModel);
                    }
                }
            });
        }
    });
}
/*WziLu/4A0kO0uBbSHZ8lDgTpCkg49kx8vyf9NtVTXT1Eb3imR5AOucqegTL/biXC*/